home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / ggraph / RCS / legend.c,v < prev    next >
Text File  |  1989-07-12  |  4KB  |  143 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     89.07.12.01.40.56;  author douglis;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @baseline from monet (?)
  17. @
  18.  
  19.  
  20.  
  21. 1.1
  22. log
  23. @Initial revision
  24. @
  25. text
  26. @#include <stdio.h>
  27. #include <errno.h>
  28. #include <strings.h>
  29. #include <math.h>
  30. #include "ggraph.h"
  31. #include "ggraphdefs.h"
  32.  
  33. /****************************************************************
  34.  *                                *
  35.  *    drawlegend - draw a legend                *
  36.  *                                *
  37.  ****************************************************************/
  38. drawlegend()
  39. {
  40.     register int i;
  41.     float legendlx, legendly;
  42.     int legend_line_len;
  43.  
  44.     if(legendbox)
  45.       drawlbox();
  46.     legendlx = cg.lframe.frame1x + 10.0;
  47.     legendly = cg.lframe.frame1y+10.0;
  48.     for (curline = 0; ((curline != cg.maxlines) && (cl != NULL)); ++curline)
  49.       if(cl->lonoff){
  50.         drawctext(legendlx+10.0, legendly, cl->llelabel.t_font,
  51.       cl->llelabel.t_size, cl->llelabel.t_text, BOTLEFT_TEXT);
  52.     legend_line_len = xcharsz[cl->llelabel.t_size] * 
  53.       strlen(cl->llelabel.t_text);
  54.     drawline(cl->ltype, legendlx+10.0, legendly-3.0,
  55.       legendlx+legend_line_len+10, legendly-3.0);
  56.     draw_symbol(cl->mtype, legendlx, legendly+5.0);
  57.     legendly = legendly + cg.ylabel.t_size * 15.0 * 0.6;
  58.       }
  59.     if (cg.legend.t_text[0] == NULL)
  60.       strcpy (cg.legend.t_text, "Legend");
  61.     drawctext((cg.lframe.frame1x+cg.lframe.frame3x)/2.0, 
  62.       cg.lframe.frame2y - 3.0, cg.legend.t_font, cg.legend.t_size,
  63.       cg.legend.t_text, TOPCENTER_TEXT);
  64.     return;
  65. }
  66.  
  67. /****************************************************************
  68.  *                                *
  69.  *    drawlbox - draw a frame around the legned        *
  70.  *                                *
  71.  ****************************************************************/
  72. drawlbox()
  73. {
  74.     drawline (cg.lframe.fsize, cg.lframe.frame1x, cg.lframe.frame1y, 
  75.       cg.lframe.frame2x, cg.lframe.frame2y);
  76.     drawline (cg.lframe.fsize, cg.lframe.frame2x, cg.lframe.frame2y, 
  77.       cg.lframe.frame3x, cg.lframe.frame3y);
  78.     drawline (cg.lframe.fsize, cg.lframe.frame3x, cg.lframe.frame3y, 
  79.       cg.lframe.frame4x, cg.lframe.frame4y);
  80.     drawline (cg.lframe.fsize, cg.lframe.frame4x, cg.lframe.frame4y, 
  81.       cg.lframe.frame1x, cg.lframe.frame1y);
  82.     return;
  83. }
  84. /****************************************************************
  85.  *                                *
  86.  *    calc_legend - calculate legend parameters        *
  87.  *                                *
  88.  ****************************************************************/
  89. calc_legend(plotx, ploty)
  90. float *plotx;
  91. float *ploty;
  92. {
  93.     int lelen, maxlelen;
  94.     float leg_width;
  95.  
  96.     maxlelen = 0;
  97.     cg.lframe.fsize = BRUSH_THIN;    /* set brush size */
  98.     for(curline=0;((curline!=MAXLINES) && (cl != NULL));++curline){
  99.       if(cl->lonoff)
  100.     if (cl->llelabel.t_text[0] == NULL)
  101.       strcpy (cl->llelabel.t_text, cl->lname); 
  102.       lelen = strlen (cl->llelabel.t_text); 
  103.       if(maxlelen < lelen)
  104.         maxlelen = lelen;
  105.     }
  106.     if(legendside){
  107. /* should compute length of longest text string and size box */
  108. /* accordingly */
  109.     *plotx = XPLOTMAX - (maxlelen * 10.0) + 20.0;    /* figure out where is starts */
  110.     if(!*ploty)
  111.       *ploty = YSCREENMIN+(ycharsz[cg.ylabel.t_size] * 3.0);
  112.     cg.lframe.frame1x = *plotx+20.0;    /* set legend boundaries */
  113.     cg.lframe.frame2x = cg.lframe.frame1x;
  114.     cg.lframe.frame3x = XSCREENMAX - 5;
  115.     cg.lframe.frame4x = cg.lframe.frame3x;
  116.     cg.lframe.frame1y = cg.yorigin;
  117.     cg.lframe.frame2y = ((cg.maxlines * ycharsz[cg.ylabel.t_size])+
  118.       (3.0*ycharsz[cg.legend.t_size]))+cg.lframe.frame1y;
  119.     cg.lframe.frame3y = cg.lframe.frame2y;
  120.     cg.lframe.frame4y = cg.lframe.frame1y;
  121.     }else{
  122.     *plotx = XPLOTMAX;        /* figure out where is starts */
  123.     if(!*ploty)
  124.       *ploty = YSCREENMIN+((cg.maxlines * ycharsz[cg.ylabel.t_size] *2.0)+
  125.       (4.0*ycharsz[cg.legend.t_size]));
  126.  
  127.     leg_width = (maxlelen * xcharsz[cg.legend.t_size]) + 20.0;    /* figure out where is starts */
  128.  
  129.     cg.lframe.frame1x = ((XSCREENMAX - XSCREENMIN) - leg_width)/2.0
  130.       + XSCREENMIN - 10.0;    /* set legend boundaries */
  131.     cg.lframe.frame2x = cg.lframe.frame1x;
  132.     cg.lframe.frame3x = cg.lframe.frame1x + leg_width + 10.0;
  133.     cg.lframe.frame4x = cg.lframe.frame3x;
  134.     cg.lframe.frame1y = YSCREENMIN+5;
  135.     cg.lframe.frame2y = ((cg.maxlines * ycharsz[cg.ylabel.t_size])+
  136.       (3.0*ycharsz[cg.legend.t_size]))+cg.lframe.frame1y;
  137.     cg.lframe.frame3y = cg.lframe.frame2y;
  138.     cg.lframe.frame4y = cg.lframe.frame1y;
  139.     }
  140.     return;
  141. }
  142. @
  143.